package com.timo.redis.config;



import com.timo.redis.constant.RedisConstant.*;
import com.timo.redis.receiv.MessageSubscriber;
import com.timo.redis.receiv.MessageSubscriberNew;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.ChannelTopic;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

import java.util.concurrent.CountDownLatch;

/**
 * @Description: 类的详细说明
 * @Author: timo
 * @Date: 2019/8/29 11:07
 */
@Slf4j
@Configuration
public class PusSubConfig {




    @Bean
    public RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
                                                   MessageListenerAdapter helloMessageListenerAdapter) {
        RedisMessageListenerContainer container = new RedisMessageListenerContainer();
        container.setConnectionFactory(connectionFactory);
        container.addMessageListener(helloNew(),helloNewTopic());
        return container;
    }

    @Bean
    public MessageSubscriberNew helloNew() {
        return new MessageSubscriberNew();
    }

    @Bean
    public ChannelTopic helloNewTopic() {
        return new ChannelTopic(SubscriptionTopicEnum.HELLO_TOPIC.topic);
    }




}
